package com.example.transaction.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.transaction.common.vo.Result;
import com.example.transaction.sys.entity.ItemClassfy;
import com.example.transaction.sys.mapper.ItemClassfyMapper;
import com.example.transaction.sys.mapper.UserMapper;
import com.example.transaction.sys.service.IItemClassfyService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zh
 * @since 2023-06-26
 */
@Service
public class ItemClassfyServiceImpl extends ServiceImpl<ItemClassfyMapper, ItemClassfy> implements IItemClassfyService {
    private final ItemClassfyMapper itemClassfyMapper ; // 假设使用MyBatis Plus的Mapper接口

    public ItemClassfyServiceImpl(ItemClassfyMapper itemClassfyMapper) {
        this.itemClassfyMapper = itemClassfyMapper;
    }

    @Override
    public Integer getItemClassfyByItemId(Integer itemId) {
        ItemClassfyMapper itemClassfyMapper = getBaseMapper();
        QueryWrapper<ItemClassfy> wrapper = new QueryWrapper<>();
        wrapper.eq("ItemID", itemId);
        ItemClassfy itemClassfy = itemClassfyMapper.selectOne(wrapper);
        if (itemClassfy != null) {
            return itemClassfy.getClassfyID();
        }
        return null;
    }

    @Override
    public List<Integer> getItemIdsByClassfyID(Integer classfyID) {
            // 假设关联表名为 item_classify，包含 itemid 和 classfyid 两个字段
            QueryWrapper<ItemClassfy> wrapper = new QueryWrapper<>();
            wrapper.eq("classfyid", classfyID);
            List<ItemClassfy> itemClassifies = itemClassfyMapper.selectList(wrapper);
            List<Integer> itemIds = new ArrayList<>();
            for (ItemClassfy itemClassfy : itemClassifies) {
                itemIds.add(itemClassfy.getItemID());
            }
            return itemIds;
    }


}
